<template>
  <div class="comparison">
    <Dialog content="科目类别：按照C02产品分类标签"></Dialog>
    <div class="table">

      <el-table v-loading="tableLoading" border style="width: 100%" :span-method="objectMethod" :cell-style="{ padding: '0px' }" :header-cell-style="{
                    background: '#0070C0',
                    color: '#ffffff',
                    padding: '0',
                    height: '26px'
                }" :data="tableData">
        <el-table-column label="科目类别1" prop="class1" align="center">
        </el-table-column>
        <el-table-column label="科目类别2" prop="class2" align="center">
        </el-table-column>
        <el-table-column label="科目类别3" prop="indexName" align="center">
        </el-table-column>
        <el-table-column label="上月" prop="lastMonthIncome" align="center" />
        <el-table-column label="本月" prop="thisMonthIncome" align="center" />
        <el-table-column label="整体环比" prop="hbMonInreaseAmt" align="center">
        </el-table-column>
        <el-table-column label="公众环比" prop="gzHb" align="center">
        </el-table-column>
        <el-table-column label="公众同比" prop="gzTb" align="center">
        </el-table-column>
        <el-table-column label="政企环比" prop="zqHb" align="center">
        </el-table-column>
        <el-table-column label="政企同比" prop="zqTb" align="center">
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
// import { getComparison } from "@/api/barCode/index";
import $barCodeApi from "@/api/barCode/index";
import Dialog from "./dialog.vue";
export default {
  name: "comparison",
  components: {
    Dialog,
  },
  props: {
    form: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      tableLoading: false,
      tableData: [],
      spanArr1: [],
      spanArr2: [],
    };
  },
  computed: {},
  created() {},
  mounted() {},
  methods: {
    getList() {
      this.tableLoading = true;

      $barCodeApi.getComparison({ ...this.form }, (res) => {
        if (res.code == 0) {
          this.tableLoading = false;
          this.tableData = res.content;
          let contactDot = 0;
          let spanArr1 = [];
          let contactDot1 = 0;
          let spanArr2 = [];
          this.tableData.forEach((item, index) => {
            if (index === 0) {
              spanArr1.push(1);
              spanArr2.push(1);
            } else {
              if (item.class1 === this.tableData[index - 1].class1) {
                spanArr1[contactDot] += 1;
                spanArr1.push(0);
              } else {
                contactDot = index;
                spanArr1.push(1);
              }
              if (item.class2 === this.tableData[index - 1].class2) {
                spanArr2[contactDot1] += 1;
                spanArr2.push(0);
              } else {
                contactDot1 = index;
                spanArr2.push(1);
              }
            }
          });
          this.spanArr1 = spanArr1;
          this.spanArr2 = spanArr2;
        }
      });

      // getComparison(this.form).then((res) => {
      //   if (res.code == 0) {
      //     this.tableLoading = false;
      //     this.tableData = res.content;
      //     let contactDot = 0;
      //     let spanArr1 = [];
      //     let contactDot1 = 0;
      //     let spanArr2 = [];
      //     this.tableData.forEach((item, index) => {
      //       if (index === 0) {
      //         spanArr1.push(1);
      //         spanArr2.push(1);
      //       } else {
      //         if (item.class1 === this.tableData[index - 1].class1) {
      //           spanArr1[contactDot] += 1;
      //           spanArr1.push(0);
      //         } else {
      //           contactDot = index;
      //           spanArr1.push(1);
      //         }
      //         if (item.class2 === this.tableData[index - 1].class2) {
      //           spanArr2[contactDot1] += 1;
      //           spanArr2.push(0);
      //         } else {
      //           contactDot1 = index;
      //           spanArr2.push(1);
      //         }
      //       }
      //     });
      //     this.spanArr1 = spanArr1;
      //     this.spanArr2 = spanArr2;
      //   }
      // });
    },
    objectMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        if (this.spanArr1[rowIndex]) {
          return {
            rowspan: this.spanArr1[rowIndex],
            colspan: 1,
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
      if (columnIndex === 1) {
        if (this.spanArr2[rowIndex]) {
          return {
            rowspan: this.spanArr2[rowIndex],
            colspan: 1,
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
    },
  },
};
</script>

<style scoped lang="scss"></style>
